// constructGenerate.cpp: implementation of the ConstructGenerate class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "phsshare.h"
#include "constructGenerate.h"
#include "JoinInfo.h"
#include "JointFunction.h"
#include "JointFactory.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

IMPLEMENT_DYNAMIC_CREATE(ConstructGenerate, JointGeneratorArithmetic, JointGeneratorArithmetic::eCONSTRUCT)
ConstructGenerate::ConstructGenerate()
{

}

ConstructGenerate::~ConstructGenerate()
{

}

BOOL ConstructGenerate::Execute(Joint *&pJoint)
{
	JointFunction* pFirstFunction = NULL;
	JointFunction* pNextFunction = NULL;

	pFirstFunction = GetFirst().GetFirst();
	while(pFirstFunction != NULL)
	{
		if(!pFirstFunction->HasJoint())
		{
			ASSERT(pFirstFunction->GetJoint() == NULL);
			pNextFunction = GetNext().GetFirst();
			while(pNextFunction != NULL )
			{
				if(!pNextFunction->HasJoint())
				{
					ASSERT(pNextFunction->GetJoint() == NULL);
					pJoint = GetJointFactory().Create(pFirstFunction, pNextFunction);
					
					if(pJoint != NULL)
						return TRUE;
				}
				pNextFunction = GetNext().GetNext();
			}
		}
		pFirstFunction = GetFirst().GetNext();
	}
	return FALSE;
}
